package indi.zjh.dp.access;

import io.netty.handler.codec.http.HttpMethod;

import java.util.Map;

public class ApiContext {
	protected HttpServer server;
	protected Map<String, String> params;
	protected StringBuffer responseBuf;
	protected HttpMethod method;
	
	public ApiContext(HttpServer server, Map<String, String> params, HttpMethod method)
	{
		this.server = server;
		this.params = params;
		this.responseBuf = new StringBuffer();
		this.method = method;
	}
	
	public int getRequestParamCount()
	{
		return this.params.size();
	}
	
	public HttpMethod getRequestMethod()
	{
		return this.method;
	}
	
	public String getRequestParamValue(String name)
	{
		if(this.params.containsKey(name))
			return this.params.get(name);
		return "";
	}
	
	public boolean hasRequestParam(String name)
	{
		return this.params.containsKey(name);
	}
	
	public void writeResponse(String content)
	{
		this.responseBuf.append(content);
	}
	
	public String getResponseContent()
	{
		return this.responseBuf.toString();
	}
}
